package com.changgou.goods.dao;

import com.changgou.goods.pojo.Brand;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface BrandMapper extends Mapper<Brand> {

    /**
     * 根据分类名称查询品牌-join
     * @param cateName
     * @return
     */
    @Select("SELECT b.* FROM tb_brand as b \n" +
            "JOIN tb_category_brand as cb on b.id = cb.brand_id\n" +
            "JOIN tb_category as c on cb.category_id = c.id\n" +
            "WHERE c.`name` = #{cateName}")
    List<Brand> findByCate(String cateName);

    /**
     * 根据分类名称查询品牌-in
     * @param cateName
     * @return
     */
    @Select("SELECT * FROM tb_brand WHERE id IN(\n" +
            "SELECT brand_id FROM tb_category_brand WHERE category_id in (\n" +
            "SELECT id FROM tb_category WHERE `name` = #{cateName}\n" +
            "))")
    List<Brand> findByCate1(String cateName);
}
